#include <ctype.h>
#include <math.h>
#include <stdlib.h>
+#include <QtCore/QRegExp>
#include "defs.h"
#include "csv_util.h"
#include "grtcirc.h"
/* usage: p = csv_stringclean(stringtoclean, "&,\"") */
/* (strip out ampersands, commas, and quotes. */
/*********************************************************************/
+
char*
#ifdef DEBUG_MEM
CSV_STRINGCLEAN(const char* string, const char* chararray, DEBUG_PARAMS)
}
QString
-csv_stringclean(const QString& string, const char* chararray)
+csv_stringclean(const QString& source, const QString& to_nuke)
{
- char *t = csv_stringclean(CSTR(string), chararray);
- QString r(t);
- xfree(t);
- return r;
+ QString r = source;
+ QString regex = QString("[%1]").arg(to_nuke);
+ return r.remove(QRegExp(regex));
}
+#if 0
char*
csv_stringclean(const QString& string_in, const QString& chararray_in)
{
// xfree(chararray);
return r;
}
+#endif
/***********************************************************************************/
/* csv_stringtrim() - trim whitespace and leading and trailing enclosures (quotes) */
return (tmp);
}
+// Is this really the replacement for the above?
+QString
+csv_stringtrim(const QString& source, const QString& enclosure)
+{
+ QString r = source;
+ r.replace(enclosure, "");
+ return r.trimmed();
+}
+
/*****************************************************************************/
/* csv_lineparse() - extract data fields from a delimited string. designed */
/* to handle quoted and delimited data within quotes. */
CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS);
#define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__)
#endif
+QString csv_stringtrim(const QString& source, const QString& enclosure);
char*
csv_lineparse(const char* stringstart, const char* delimited_by, const char* enclosed_in, const int line_no);
CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS);
#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__)
#endif
-QString csv_stringclean(const QString& string, const char* chararray);
+QString csv_stringclean(const QString& string, const QString& chararray);
void
xcsv_data_read(void);
}
void
-ozi_set_time_str(const char* str, waypoint* waypointp)
+ozi_set_time_str(const QString& str, waypoint* waypointp)
{
- double ozi_time = atof(str);
+ double ozi_time = str.toDouble();
if (ozi_time > DAYS_SINCE_1990) {
waypointp->SetCreationTime((ozi_time - DAYS_SINCE_1990) * SECONDS_PER_DAY,
}
static void
-ozi_parse_waypt(int field, char* str, waypoint* wpt_tmp, ozi_fsdata* fsdata)
+ozi_parse_waypt(int field, const QString& str, waypoint* wpt_tmp, ozi_fsdata* fsdata)
{
double alt;
- if (*str == '\0') {
+ if (str.isEmpty()) {
return;
}
break;
case 1:
/* waypoint name */
- wpt_tmp->shortname = csv_stringtrim(str, "", 0);
+ wpt_tmp->shortname = csv_stringtrim(str, "");
break;
case 2:
/* degrees latitude */
- wpt_tmp->latitude = atof(str);
+ wpt_tmp->latitude = str.toDouble();
break;
case 3:
/* degrees longitude */
- wpt_tmp->longitude = atof(str);
+ wpt_tmp->longitude = str.toDouble();
break;
case 4:
/* DAYS since 1900 00:00:00 in days.days (5.5) */
tables are, so we read just the numbers. This converts badly to
other types, but it at least maintains fidelity for an ozi->ozi
operation. */
- if (str && isdigit(str[0])) {
+ if (str.toInt() > 0) {
wpt_tmp->icon_descr = str;
}
break;
break;
case 8:
/* foreground color (0=black) */
- fsdata->fgcolor = atoi(str);
+ fsdata->fgcolor = str.toInt();
break;
case 9:
/* background color (65535=yellow) */
- fsdata->bgcolor = atoi(str);
+ fsdata->bgcolor = str.toInt();
break;
case 10:
/* Description */
- wpt_tmp->description = csv_stringtrim(str, "", 0);
+ wpt_tmp->description = csv_stringtrim(str, "");
break;
case 11:
/* pointer direction 0,1,2,3 bottom,top,left,right */
break;
case 13:
/* proximity distance - meters */
- WAYPT_SET(wpt_tmp, proximity, atof(str) * prox_scale);
+ WAYPT_SET(wpt_tmp, proximity, str.toDouble() * prox_scale);
break;
case 14:
/* altitude */
- alt = atof(str);
+ alt = str.toDouble();
if (alt == -777) {
wpt_tmp->altitude = unknown_alt;
} else {
break;
case 4:
/* waypoint name */
- wpt_tmp->shortname = csv_stringclean(str, ",");
+ wpt_tmp->shortname = csv_stringclean(str, QString(","));
break;
case 5:
/* latitude */
break;
case 13:
/* description */
- wpt_tmp->description = csv_stringclean(str, ",");
+ wpt_tmp->description = csv_stringclean(str, QString(","));
break;
default:
break;
}
static void
-ozi_parse_routeheader(int field, char* str, waypoint* wpt_tmp)
+ozi_parse_routeheader(int field, const QString& str, waypoint* wpt_tmp)
{
switch (field) {
break;
case 1:
/* route # */
- rte_head->rte_num = atoi(str);
+ rte_head->rte_num = str.toInt();
break;
case 2:
/* route name */
break;
case rtedata:
if (buff[0] == 'R') {
- ozi_parse_routeheader(i, s, wpt_tmp);
+ ozi_parse_routeheader(i, QString(s), wpt_tmp);
header = true;
} else {
ozi_parse_routepoint(i, s, wpt_tmp);
{
char* buff;
char* s;
- char* holder;
waypoint* wpt_tmp;
int i;
int linecount = 0;
/* ignore: group */
break;
case 1:
- wpt_tmp->shortname = csv_stringtrim(s, "", 0);
+ wpt_tmp->shortname = csv_stringtrim(s, "");
break;
case 2:
/* Description is not a TopoMapPro format requirement.
If we assign "" then .loc/.gpx will generate empty XML tags :(
*/
- holder = csv_stringtrim(s, "", 0);
- if (strlen(holder)) {
- wpt_tmp->description = holder;
- } else {
- xfree(holder);
- }
+ wpt_tmp->description = csv_stringtrim(s, "");
break;
case 3:
wpt_tmp->latitude = atof(s);
use the TopoMapLinks links.
(plus discards length 0 strings (so no empty XML tags))
*/
- holder = csv_stringtrim(s, "", 0);
- if (strstr(holder, "http:") != NULL) {
- wpt_tmp->AddUrlLink(holder);
+ {
+ QString link = csv_stringtrim(s, "");
+ if (link.contains("http:")) {
+ wpt_tmp->AddUrlLink(link);
+ }
}
- xfree(holder);
break;
default:
/* whoa! nelly */